using Elderlyhealth.BLL;
using Elderlyhealth.DAL;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;


public partial class ChangePwd : System.Web.UI.Page
{
    CustomerService customerSrv = new CustomerService();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["CustomerId"] == null)  //用户未登录
        {
            Response.Redirect("~/Login.aspx");
        }

        // 如果是调试模式，插入测试数据
        // 如果你不再需要插入测试数据，可以完全删除这个部分
#if DEBUG
    if (!IsPostBack)
    {
        using (var db = new DataClasses1DataContext())
        {
            try
            {
                Feedback feedback = new Feedback
                {
                    FeedbackText = "测试数据",
                    SubmittedAt = DateTime.Now
                };

                db.Feedback.InsertOnSubmit(feedback);
                db.SubmitChanges();
            }
            catch (Exception ex)
            {
                // 在页面上显示错误信息
                lblMsg.Text = "插入测试数据失败: " + ex.Message;
            }
        }
    }
#endif
    }


    protected void btnChangePwd_Click1(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            //调用CustomerService类中的CheckLogin()方法检查Session变量CustomerName关联的用户名和输入的原密码，返回值大于0表示输入的原密码正确
            if (customerSrv.CheckLogin(Session["CustomerName"].ToString(), txtOldPwd.Text) > 0)
            {
                customerSrv.ChangePassword(Convert.ToInt32(Session["CustomerId"]), txtPwd.Text);
                lblMsg.Text = "密码修改成功！";
            }
            else  //输入的原密码不正确
            {
                lblMsg.Text = "原密码不正确！";
            }
        }
    }
    [WebMethod]
    public static string SubmitFeedback(string feedbackText)
    {
        try
        {
            // 输出调试信息
            System.Diagnostics.Debug.WriteLine("接收到的反馈内容：" + feedbackText);

            using (var db = new DataClasses1DataContext())
            {
                Feedback feedback = new Feedback
                {
                    FeedbackText = feedbackText,
                    SubmittedAt = DateTime.Now
                };
                db.Feedback.InsertOnSubmit(feedback);
                db.SubmitChanges();
            }

            return "反馈提交成功！";
        }
        catch (Exception ex)
        {
            return "提交失败：" + ex.Message;
        }
    }







}